﻿using System;
using System.Linq;
using DZLib.ExtendFramework.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DZLib.ExtendFramework.UnitTests.Generic.ExtendIEnumerableTest
{
    [TestClass]
    public class SetSpliteTest
    {
        [TestMethod]
        public void SetSpliteNormTest()
        {
            var target = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var splites = new int[] { 2, 4, 8, 0 };
            var expected = new int[4][];
            expected[0] = new int[] { 1 };
            expected[1] = new int[] { 3 };
            expected[2] = new int[] { 5, 6, 7 };
            expected[3] = new int[] { 9 };
            var actual = target.SetSplit(splites).ToArray();
            for (int i = 0; i < expected.Count(); i++)
            {
                Assert.IsTrue(expected[i].SequenceEqual(actual[i]));
            }
        }

        [TestMethod]
        public void SetSpliteLowBoundTest()
        {
            var target = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var splites = new int[] { };
            try
            {
                var actual = target.SetSplit(splites).ToArray();
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }
        }

        [TestMethod]
        public void SetSpliteMissTest()
        {
            var target = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var splites = new int[] { 2, 4, 8, 0, 11, 23 };
            var expected = new int[4][];
            expected[0] = new int[] { 1 };
            expected[1] = new int[] { 3 };
            expected[2] = new int[] { 5, 6, 7 };
            expected[3] = new int[] { 9 };
            var actual = target.SetSplit(splites).ToArray();
            for (int i = 0; i < expected.Count(); i++)
            {
                Assert.IsTrue(expected[i].SequenceEqual(actual[i]));
            }
        }

        [TestMethod]
        public void SetSpliteEmptyTest()
        {
            var target = new int[] { };
            var splites = new int[] { 2, 4, 8, 0, 11, 23 };
            var expected = new int[1][];
            expected[0] = new int[] { };
            var actual = target.SetSplit(splites).ToArray();
            for (int i = 0; i < expected.Count(); i++)
            {
                Assert.IsTrue(expected[i].SequenceEqual(actual[i]));
            }
        }

        [TestMethod]
        public void SetSpliteFullMissTest()
        {
            var target = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var splites = new int[] { 12, 14, 18, 20, 11, 23 };
            var expected = new int[1][];
            expected[0] = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var actual = target.SetSplit(splites).ToArray();
            for (int i = 0; i < expected.Count(); i++)
            {
                Assert.IsTrue(expected[i].SequenceEqual(actual[i]));
            }
        }
    }
}
